﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace pintu
{
    public sealed partial class TextoperateControl : UserControl
    {
        Canvas canvas = null;
        TextBlock tb;
        public TextoperateControl()
        {
            this.InitializeComponent();
        }
        public TextoperateControl(Canvas _canvas,TextBlock _tb)
        {
            this.InitializeComponent();
            canvas = _canvas;
            tb = _tb;

        }
        private void delete_Click(object sender, RoutedEventArgs e)
        {
            canvas.Children.Remove(tb);
        }

        private void scalebox_TextChanged(object sender, TextChangedEventArgs e)
        {
            Settransform();
        }

        private void okbtn_Click(object sender, RoutedEventArgs e)
        {
            (this.Parent as Popup).IsOpen = false;
        }

        private void rotatebox_TextChanged(object sender, TextChangedEventArgs e)
        {
            Settransform();
        }
        private void Border_LostFocus(object sender, RoutedEventArgs e)
        {
            //if((this.Parent as Popup )!= null)
            //(this.Parent as Popup).IsOpen = false;
        }
        private void Settransform()
        {
            TransformGroup grouptransform = new TransformGroup();
            if (!string.IsNullOrEmpty(scalebox.Text))
            {
                ScaleTransform scaletransform = new ScaleTransform();
                scaletransform.ScaleX = double.Parse(scalebox.Text);
                scaletransform.ScaleY = double.Parse(scalebox.Text);
                grouptransform.Children.Add(scaletransform);
            }
            if (!string.IsNullOrEmpty(rotatebox.Text))
            {
                RotateTransform rotate = new RotateTransform();
                rotate.Angle = double.Parse(rotatebox.Text);
                grouptransform.Children.Add(rotate);
            }
            tb.RenderTransform = grouptransform;
        }

       
    }
}
